package cn.matrix42.potoo.jdbc.connection;

import cn.matrix42.potoo.lang.Preconditions;

import java.util.Properties;

public class ConnectionInfoBuilder {

    private final ConnectionInfo connectionInfo = new ConnectionInfo();

    public static ConnectionInfoBuilder newConnectionInfoBuilder() {
        return new ConnectionInfoBuilder();
    }

    public ConnectionInfoBuilder withUsername(String username) {
        Preconditions.checkNotNull(username);
        connectionInfo.setUsername(username);
        return this;
    }

    public ConnectionInfoBuilder withPassword(String password) {
        connectionInfo.setPassword(password);
        return this;
    }

    public ConnectionInfoBuilder withUrl(String url) {
        Preconditions.checkNotNull(url);
        connectionInfo.setUrl(url);
        return this;
    }

    public ConnectionInfoBuilder withProperties(Properties properties) {
        Preconditions.checkNotNull(properties);
        connectionInfo.setProperties(properties);
        return this;
    }

    public ConnectionInfo build() {
        Preconditions.checkNotNull(connectionInfo.getUsername());
        Preconditions.checkNotNull(connectionInfo.getUrl());
        return connectionInfo;
    }

}
